/*
 * Copyright (c) 2019 Winner Microelectronics Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-12     fanwenl      1st version
 */

#ifndef __EXT_GPIO_CONTROL_THREAD_H_
#define __EXT_GPIO_CONTROL_THREAD_H_

#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "delay.h"
#include "stdint.h"

typedef union
{
	struct
	{
		uint16_t OC0 : 1;  // S1_7
		uint16_t OC1 : 1;  // S1_6
		uint16_t OC2 : 1;  // S1_5
		uint16_t OC3 : 1;  // S1_4
		uint16_t OC4 : 1;  // S1_3
		uint16_t OC5 : 1;  // S1_2
		uint16_t OC6 : 1;  // S1_1
		uint16_t OC7 : 1;  // S1_D
		uint16_t OC8 : 1;  // S2_D
		uint16_t OC9 : 1;  // S2_1
		uint16_t OC10 : 1; // S2_2
		uint16_t OC11 : 1; // S2_3
		uint16_t OC12 : 1; // S2_4
		uint16_t OC13 : 1; // S2_5
		uint16_t OC14 : 1; // S2_6
		uint16_t OC15 : 1; // S2_7
	} state;
	uint16_t oc_port;
} Ch423_OC_Output_Typedef;

typedef union
{
	struct
	{
		uint16_t IO0 : 1; // S2_8
		uint16_t IO1 : 1; // S2_9
		uint16_t IO2 : 1; // S2_0
		uint16_t IO3 : 1; // speech_power_switch,low to active
		uint16_t IO4 : 1; // speech_uart_switch
		uint16_t IO5 : 1; // S1_0
		uint16_t IO6 : 1; // S1_9
		uint16_t IO7 : 1; // S1_8
	} state;
	uint8_t io_port;
} Ch423_IO_Output_Typedef;

struct ch423_ext_gpio_control_reg
{
	Ch423_OC_Output_Typedef ch423_oc_port;
	Ch423_IO_Output_Typedef ch423_io_port;
};

typedef struct ch423_ext_gpio_control_reg ch423_ext_gpio_control_reg_t;

void set_speech_module_uart_to_mcu(void);
void set_speech_module_uart_to_usb2ttl(void);
void set_speech_module_power_on(void);
void set_speech_module_power_off(void);

void set_left_nixie_cube_number(uint8_t left_number);
void set_left_nixie_cube_dot(rt_bool_t dot);
void set_right_nixie_cube_number(uint8_t right_number);
void set_right_nixie_cube_dot(rt_bool_t dot);

void open_nixie_tube(void);
void shut_nixie_tube(void);

#endif /* __EXT_GPIO_CONTROL_THREAD_H_ */
